package com.yanqu.road.server.cmd.minewar.task;

import com.yanqu.road.pb.minewar.MineWarProto;
import com.yanqu.road.server.cmd.base.BaseTask;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.MineWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

public class RobPitTask extends BaseTask {

	private int mineType;

	private int pitId;

	private long pitOwnerUserId;

	private List<Integer> patronsIdList;

	public RobPitTask(YanQuMessage packet, GamePlayer player) {
		super(packet, player);
	}

	@Override
	protected boolean parseData() throws Exception {
		MineWarProto.MinePitRobReqMsg reqMsg = MineWarProto.MinePitRobReqMsg.parseFrom(packet.getBytes());
		mineType = reqMsg.getMineType();
		pitId = reqMsg.getPitId();
		pitOwnerUserId = reqMsg.getPitOwnerUserId();
		patronsIdList = new ArrayList<>();
		for(Integer patronsId : reqMsg.getPatronsIdListList()){
			if(!patronsIdList.contains(patronsId)){
				patronsIdList.add(patronsId);
			}
		}
		return true;
	}

	@Override
	protected void execute() {
		long nowTime = System.currentTimeMillis();
		player.sendPacket(Protocol.U_MINE_WAR_ROB_PIT, MineWarMgr.robPit(player, mineType, pitId, pitOwnerUserId, patronsIdList));
		logger.info("mine battle cost time:{}", System.currentTimeMillis() - nowTime);
	}

	@Override
	protected void sendData(GamePlayer player) {

	}

}
